<script>
	$(".exenterprise").live('click', function(){
		if(confirm('Deseja realmente deletar essa empresa?')){
			url = "/admin/delete-enterprise?enterprise_id="+$(this).attr('id');
			$.ajax({
	            type: 'GET',
	            url: url,
	            success:function(data){
	            	$('#list-enterprise').html(data);
	            },
				error: function(){
			   		alert('failure');
			  	}
	        });
		}
	});

	$(".excategory").live('click', function(){
		if(confirm('Deseja realmente deletar essa categoria?')){
			url = "/admin/delete-category?id_category="+$(this).attr('id');

			$.ajax({
	            type: 'GET',
	            url: url,
	            success:function(data){
	            	$('#list-category').html(data);
	            },
				error: function(){
			   		alert('failure');
			  	}
	        });
		}
	});
</script>

<h2 class="partner-title" style="width: 100%;">Produtos Cadastrados</h2>
<div id="list-content">
<div class="search-header">
		<span>
			<a href="../admin/new-product" >Novo Produto</a>
		</span>
		<span>
			Buscar Produto: <input type="text" id="search" name="search" onkeyup="getPaginatedAdminProducts('/admin/search-product', 'list-products')">
		</span>
		<span>
			Preço: 
				<select id="searchPrice" name="searchPrice" onchange="getPaginatedAdminProducts('/admin/search-product', 'list-products')">
					<option selected="selected" value="">Selecione</option>
					<option value="price < 10">menos de R$10,00</option>
					<option value="price BETWEEN 10 AND 20">entre R$10,00 e R$20,00</option>
					<option value="price BETWEEN 20 AND 30">entre R$20,00 e R$30,00</option>
					<option value="price BETWEEN 10 AND 20">entre R$30,00 e R$40,00</option>
					<option value="price BETWEEN 10 AND 20">entre R$50,00 e R$60,00</option>
					<option value="price BETWEEN 10 AND 20">entre R$60,00 e R$70,00</option>
					<option value="price BETWEEN 10 AND 20">entre R$70,00 e R$80,00</option>
					<option value="price BETWEEN 10 AND 20">entre R$80,00 e R$90,00</option>
					<option value="price BETWEEN 10 AND 20">entre R$90,00 e R$100,00</option>
					<option value="price > 100">mais de R$100,00</option>
				</select>
		</span>		
	</div>
<div id="list-products">
	<?php echo sizeof($this->listAll);?>
	<?php if ($this->listAll != null):?>
<div style="height: 35px;">
	<h2 class="partner-title" style="width: 25%;">Nome</h2>
	<h2 class="partner-title" style="width: 15%;">Empresa</h2>
	<h2 class="partner-title" style="width: 15%;">Ano</h2>
	<h2 class="partner-title" style="width: 15%;">Preço</h2>
	<h2 class="partner-title" style="width: 15%;">Qtd Estoque</h2>
	<h2 class="partner-title" style="width: 15%;">Disponível</h2>
</div>

<dl>
<?php foreach ($this->listAll as $result):?>
	<dt>
		<a title="<?php echo $result['name']?>" href="/admin/view-edit?product=<?php echo $result['id_product']?>" class="transaction" style="width: 25%;"
			name="<?php echo $result['name']?>"> 
			<?php if(strlen($result['name']) > 22):?>
				<?php echo substr($result['name'], 0, 22).'...'?> 
			<?php else:?>
				<?php echo $result['name']?>
			<?php endif;?>
		</a> 
		<a href="/admin/view-edit?product=<?php echo $result['id_product']?>" class="transaction" style="width: 15%;"
			name="<?php echo utf8_encode($result['title'])?>"> 
			<?php if(strlen(utf8_encode($result['title'])) > 17):?>
				<?php echo substr(utf8_encode($result['title']), 0, 17).'...'?> 
			<?php else:?>
				<?php echo utf8_encode($result['title'])?>
			<?php endif;?>
		</a>
		<a href="/admin/view-edit?product=<?php echo $result['id_product']?>" class="transaction" style="width: 15%;"
			name="<?php echo $result['year']?>"> <?php echo $result['year'];?>
		</a> 
		<a href="/admin/view-edit?product=<?php echo $result['id_product']?>" class="transaction" style="width: 15%;"
			name="<?php echo $result['price']?>"> <?php echo $result['price'];?>
		</a> 
		<a href="/admin/view-edit?product=<?php echo $result['id_product']?>" class="transaction" style="width: 15%;"
			name="<?php echo $result['quantity']?>"> 
			<?php echo $result['quantity']?>
		</a>
		<input  style="width: 15%;" class="disponivel" type="checkbox" <?php echo 'alt = "' . $result['id_product'] . '"'; if($result['status']) { echo 'checked="checked"';}?>>
	</dt>
	<dd>
		<ul>
			<li>
				<div id="<?php echo $request['id_transaction']?>"></div>
			</li>
		</ul>
	</dd>
	<?php endforeach;?>
	<!-- PAGINAÇÃO -->
		<?php echo $this->paginationControl($this->listAll, 'Sliding', '/admin/_pagination-solicitation.phtml'); ?>
	<!-- [END] PAGINAÇÃO -->
</dl>
	<?php else:?>
	<dl>
		<dt class="nothing">
			<p>Nenhum produto cadastrado!</p>
		</dt>
	</dl>
<?php endif;?>
</div>

<div id="sub-prod" style="width: 100%; min-height: 200px; margin-top: 70px;">
	<div id="list-enterprises" style="float: left; width: 45%; height: 100%">
		<div class="search-header">
		<span>
			<a href="../admin/new-enterprise">Nova Empresa</a>
		</span>
	</div>
		<?php if ($this->listAll != null):?>
	<div style="height: 35px;">
		<h2 class="partner-title" style="width: 100%;">Empresas</h2>
	</div>
	<dl style="width: 100%; float: left;">
	<?php $x = 1; foreach ($this->listEnterprises as $enterprise):?>
		<dt >
			<a class="transaction" href="#" title="Clique p/ Editar" style="float: left">
				<span ><?php echo utf8_encode($enterprise['enterprise_name']);?></span> 
			</a>
			<a id="<?php echo $enterprise['enterprise_id']?>" class="exenterprise" title="Deletar <?php echo utf8_encode($enterprise['enterprise_name']);?>?" href="#" style="float: right;">
				<img alt="" src="../images/trash.png"> 
			</a>
		</dt>
		<dd>
			<ul>
				<li>
					<div id="<?php echo $request['id_transaction']?>"></div>
				</li>
			</ul>
		</dd>
		<?php endforeach;?>
	</dl>
		<?php else:?>
	<div class="nothing">
		<p>Nenhuma empresa encontrada!</p>
	</div>
	<?php endif;?>
	</div>
	
	<div id="list-category" style="float: right; width: 45%; height: 100%">
		<div class="search-header">
		<span>
			<a href="../admin/new-category">Nova Categoria</a>
		</span>
	</div>
		<?php if ($this->listAll != null):?>
	<div style="height: 35px;">
		<h2 class="partner-title" style="width: 100%;">Categorias</h2>
	</div>
	<dl style="width: 100%; ">
	<?php $x = 1; foreach ($this->listCategories as $category):?>
		<dt >
			<a href="#" title="Clique p/ Editar" class="transaction">
				<span><?php echo $category['desc'];?></span> 
			</a> 
			<a id="<?php echo $category['id_category']?>" class="excategory" title="Deletar <?php echo utf8_encode($category['desc']);?>?"	href="#" style="float: right;">
				<img alt="" src="../images/trash.png"> 
			</a>
		</dt>
		<dd>
			<ul>
				<li>
					<div id="<?php echo $request['id_transaction']?>"></div>
				</li>
			</ul>
		</dd>
		<?php endforeach;?>
	</dl>
		<?php else:?>
	<div class="nothing">
		<p>Nenhuma categoria encontrada!</p>
	</div>
	<?php endif;?>
	</div>
</div>
	
</div>

<div class="clear"></div>
